﻿using Ext.Net;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Index : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitMenuTree();
    }

    private void InitMenuTree()
    {
        //加载菜单
        Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
        treeNode.Nodes.AddRange(LoadNodeCollection("0"));
        tabTree.Root.Add(treeNode);

    }


    private Ext.Net.TreeNodeCollection LoadNodeCollection(string menu_no)
    {
        Ext.Net.TreeNodeCollection nodes = new Ext.Net.TreeNodeCollection();
        DataTable dtMenuTree = CommonLib.BLL.SYS_MENU.GetMenuTree(BS_LoginUserID, menu_no, "9");//a.subsystem.ToString()
        foreach (DataRow item in dtMenuTree.Rows)
        {
            if (!Convert.ToBoolean(item["is_leaf"]))    //包含子节点
            {
                Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                treeNode.Text = item["menu_name"].ToString();
                treeNode.NodeID = item["menu_no"].ToString();
                treeNode.Leaf = false;
                var lnc = LoadNodeCollection(treeNode.NodeID);
                nodes.Add(treeNode);
                treeNode.Nodes.AddRange(lnc);
            }
            else    //无子节点实现
            {
                Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                treeNode.Text = item["menu_name"].ToString();
                treeNode.NodeID = item["menu_no"].ToString();
                treeNode.Leaf = true;
                string url_address = item["url_address"].ToString();
                treeNode.Href = string.Format("{0}{1}{2}tabid={3}", Request.ApplicationPath, url_address, (url_address.Contains("?") ? "&" : "?"), treeNode.NodeID);
                nodes.Add(treeNode);
            }
        }
        return nodes;
    }


    
}